﻿using FunArts.EasyDevOps.Shared.Models.Enums;
using FunArts.EasyDevOps.Shared.Utils;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FunArts.EasyDevOps.Shared.Models.SshClient.Command
{
    /// <summary>
    /// 查看已安装软件命令
    /// </summary>
    public class SearchAppCommand : ILinuxCommand
    {
        public string AppName { get; set; }
        public string BuildCommand(SystemVersionTypeEnum systemVersionType)
        {
            if (AppName.ToLower() == "java")
            {
                return "java -version 2>&1";
            }

            if (AppName.ToLower() == "nginx")
            {
                return "nginx -v 2>&1";
            }if (AppName.ToLower() == "keepalived")
            {
                return "keepalived --version 2>&1";
            }
            switch (systemVersionType)
            {
                case SystemVersionTypeEnum.Ubuntu:
                    return $"dpkg -l"+ (AppName.IsNullOrWhiteSpace() ? "" : $" | grep {AppName}");
                case SystemVersionTypeEnum.CentOS:
                    return AppName.IsNullOrWhiteSpace()? "rpm -qa" : $"rpm -q {AppName}";
                case SystemVersionTypeEnum.Windows:
                    return string.Empty;
                default:
                    return string.Empty;
            }
        }
    }
}
